<?php

class csTpl {
	
	public $tpl_tbl;
	public $tpl_vars;
	public $tpl_funcions_obj;
	public $debug_mode = false;

	public function __construct($params = null) {
		$this -> tpl_vars = array(
		);
		$this -> tpl_tbl = array(
		);
		$this -> tpl_funcions_obj = new csTplFunctions($this);
	}

	public function display($tpl_file_name) {
		$tpl_tbl = & $this -> tpl_tbl;
		$tpl_vars = & $this -> tpl_vars;
		$tpl_func = & $this -> tpl_funcions_obj;
		
		if ($this -> debug_mode) {
			echo "<!-- START $tpl_file_name -->\n";
		}
		include ($tpl_file_name);
		if ($this -> debug_mode) {
			echo "<!-- END $tpl_file_name -->\n";
		}
	}

	public function fetch($tpl_file_name) {
		ob_start();
		
		$this -> display($tpl_file_name);
		
		$tpl_content = ob_get_contents();
		ob_end_clean();
		
		return $tpl_content;
	}
}

class csTplFunctions {
	protected $tpl_obj;

	public function __construct(&$tpl_obj, $params = null) {
		$this -> tpl_obj = & $tpl_obj;
	}

	public function mod_default($string, $default = '') {
		if (! isset($string) || $string == '') {
			return $default;
		} else {
			return $string;
		}
	}
}

?>
